﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.ServiceModel.Syndication;
using System.Xml;
namespace Presentation.Web.Core.RssFeeds
{
    public class RssResult : FileResult
    {
        //public const String host = "http://localhost:2254/Store/Details/";
        //public List<Products> products { get; set; }
        //public string tilte { get; set; }

        //private Uri currentUrl;
        public RssResult() : base("application/rss+xml") { }
        //public RssResult(List<Products> products, String tilte)
        //    : this()
        //{
        //    this.products = products;
        //    this.tilte = tilte;
        //}

        public override void ExecuteResult(ControllerContext context)
        {
            //currentUrl = context.RequestContext.HttpContext.Request.Url;
            base.ExecuteResult(context);
        }
        protected override void WriteFile(HttpResponseBase response)
        {
            //var items = new List<SyndicationItem>();

            //foreach (Products product in this.products)
            //{
            //    string contentString = String.Format("there is a new Album {0} with price {1}", product.ProductName, product.BuyPrice);
            //    var item = new SyndicationItem(
            //        title: product.ProductName,
            //        content: contentString,
            //        itemAlternateLink: new Uri(host + product.ProductId)
            //      );
            //    item.Summary = new TextSyndicationContent(contentString);
            //    items.Add(item);
            //}
            //SyndicationFeed feed = new SyndicationFeed(this.tilte, this.tilte, currentUrl, items);
            //Rss20FeedFormatter formatter = new Rss20FeedFormatter(feed);
            //using (XmlWriter writer = XmlWriter.Create(response.Output))
            //{
            //    formatter.WriteTo(writer);
            //}
        }
    }
}